import axios from "axios";

// 新增帖子
export async function addPost(obj) {
  let { poster, title, content, state, tags, comments, createTime } = obj;
  let resp = await axios.post("/api/posts/", {
    poster,
    title,
    content,
    state,
    tags,
    comments,
    createTime,
  });
  return resp;
}

// 删除帖子
export async function deletePost(_id) {
  let resp = await axios.delete(`/api/posts/${_id}`);
  return resp;
}

// 查找所有的帖子
export async function getPosts(page, limit) {
  let resp = await axios.get("/api/posts/", {
    params: {
      current: page,
      pageSize: limit,
    },
  });
  console.log(resp)
  return resp;
}

// 按id查找帖子
export async function getPostById(_id) {
  let resp = await axios.get(`/api/posts/${_id}`);
  return resp;
}

// 修改帖子
export async function modifyPost(obj) {
  let { _id, poster, title, content, state, tags, comments, createTime } = obj;
  let resp = await axios.put(`/api/posts/${_id}`, {
    poster,
    title,
    content,
    state,
    tags,
    comments,
    createTime,
  });
  return resp;
}